<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
 ! Excerpted from "Mastering Dojo",
 ! published by The Pragmatic Bookshelf.
 ! Copyrights apply to this code. It may not be used to create training material, 
 ! courses, books, articles, and the like. Contact us if you are in doubt.
 ! We make no guarantees that this code is fit for any purpose. 
 ! Visit http://www.pragmaticprogrammer.com/titles/rgdojo for more book information.
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Heirarchies in JavaScript</title>
    <style type="text/css">
        @import "/dojoroot/dijit/themes/tundra/tundra.css";
        @import "/dojoroot/dojo/resources/dojo.css"
    </style>
    <script type="text/javascript" src="/dojoroot/dojo/dojo.js"  djConfig="parseOnLoad: true,isDebug:true"></script>
    <script type="text/javascript">
       dojo.require("dojo.parser");

       
       dojo.require("dojo.data.ItemFileReadStore");
       var ordJson = new dojo.data.ItemFileReadStore( {
           url: "datasources/order_combined.json",
           childrenAttr: "line"         
       }); 
       dojo.require("dojox.data.XmlStore");
       var ordXml = new dojox.data.XmlStore( {
           url: "datasources/order_combined.xml",         
           rootItem: "order", 
           keyAttribute:"orderNumber", 
           label:"description"
       }); 
       

       
       function commonComplete(storeDescription, dataStore, items, request) {
           // Get the first order
           var firstOrder = items[0];
           
           // Get array of each line from the lines list
           var lineList = dataStore.getValues(firstOrder,"line");
           
           // Get description of the first item.  The +"" applies toString()
           // to the value, necessary for XmlStore
           console.debug(
               storeDescription,
               dataStore.getValue(lineList[0],"description")+
               ""
           );
       }
       
       // Example 1: ItemFileReadStore and JSON
       ordJson.fetch({ 
          query: { id: '*' },
          onComplete: function(items, request) {
             commonComplete("JSON Native Nesting: ", ordJson, items,request);
          }
       });
       // Example 2: XmlStore 
       ordXml.fetch({ 
          query: { orderNumber: '*' },
          onComplete: function(items, request) {
             commonComplete("XML: ", ordXml, items, request);
          }
      });
      

    </script>
    
    
</head>
<body class="tundra">
</body>
</html>